/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.

* File main.cpp
* Description: AIPainting sample main func
*/

#include <iostream>
#include <stdlib.h>
#include <dirent.h>
#include "painting_process.h"
#include "utils.h"

using namespace std;

const char* omModelPath = "../model/AIPainting_v2.om";
//模型输入数据接口
//string objectInfoPath =  "../data/objs_0.bin";
//string layoutDataPath =  "../data/coarse_layout_0.bin";

string objectInfoPath =  "../data/objects.bin";
string layoutDataPath =  "../data/layout.bin";

bool g_isDevice = false;

int main(int argc, char *argv[]) {
    //检查应用程序执行时的输入,程序执行要求输入目录参数
//    if((argc < 2) || (argv[1] == nullptr)){
//        ERROR_LOG("Please input: ./main <image_dir>");
//        return FAILED;
//    }

    //实例化推理对象,参数为模型路径
    PaintingProcess painting(omModelPath, objectInfoPath, layoutDataPath);
    //初始化推理的acl资源, 模型和内存
    Result ret = painting.Init();
    if (ret != SUCCESS) {
        ERROR_LOG("AIPainting init resource failed");
        return FAILED;
    }

    //逐帧推理
    while(1)
    {
        //预处理
        Result ret = painting.Preprocess();
        if (ret != SUCCESS) {
            ERROR_LOG("Read file input data failed, continue to read next.");
//            continue;
        }

        //将预处理的图片送入模型推理,并获取推理结果
        aclmdlDataset* inferenceOutput = nullptr;
        ret = painting.Inference(inferenceOutput);
        if ((ret != SUCCESS) || (inferenceOutput == nullptr)) {
            ERROR_LOG("Inference model inference output data failed");
            return FAILED;
        }

        //解析推理输出图片,推流
        ret = painting.Postprocess(inferenceOutput);
        if (ret != SUCCESS) {
            ERROR_LOG("Process model inference output data failed");
            return FAILED;
        }
    }

    INFO_LOG("Execute sample success");
    return SUCCESS;
}
